package org.kx;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.kx.bean.Student;
import org.kx.utils.MyBatisUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Hello world!
 */
public class App2 {
    public static void main(String[] args) throws IOException {
        //（*）获取SqlSession对象，从工具类MyBatisUtils中获取SqlSession
        SqlSession sqlSession= MyBatisUtils.getSqlSession();
        //（*）指定要执行的sql语句的标识。sql映射文件中的namespace+"."+标签中的id值
        String sqlId="org.kx.dao.StudentDao"+"."+"selectStudents";
        //执行sql，通过sqlId找到语句
        List<Student> studentList= sqlSession.selectList(sqlId);
        //输出结果
        studentList.forEach(student -> System.out.println("查询的学生="+student));
        //关闭SqlSession对象
        sqlSession.close();
    }
}
